Skip to content

Add tuple argument to ip_network #8634

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 27, 2022
Merged

Conversation

@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit uneasy about this change. It's true that it works at runtime, but passing a tuple in here seems to be entirely undocumented and untested, so I feel like it could change at any time without any backwards-compatibility guarantees.

@sobolevn
Copy link
Member Author

I don't have any opinion really

@Akuli
Copy link
Collaborator

Akuli commented Aug 27, 2022

We should in general type things as the implementation does it, not as documented. I think it applies here too. I also don't see any reason why tests for this function should check with all types that IPv4Network and IPv6Network accept, even though that's the intention; that would make the tests longer without increasing the test coverage.

If someone still feels "uneasy" about this, we could add a test case -- again, nothing too thorough, could be for example the two examples in the issue.

@Akuli
Copy link
Collaborator

Akuli commented Aug 27, 2022

And I just realized that adding a test case to typeshed would be pointless, as those don't run at runtime :) I still think we should support this, because it works.

@AlexWaygood
Copy link
Member

AlexWaygood commented Aug 27, 2022

I still think we should support this, because it works.

I'm fine with this being merged, just don't necessarily want to be the one to hit "merge" myself :)

I agree that in general, we should follow the implementation rather than the documentation.

@Akuli
Copy link
Collaborator

Akuli commented Aug 27, 2022

Passing in a tuple seems to be a common pattern: https://grep.app/search?q=ip_network%28%28

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm convinced.

@AlexWaygood AlexWaygood merged commit 6d5fd0e into python:master Aug 27, 2022
@sobolevn
Copy link
Member Author

🥳

@zed
Copy link

zed commented Sep 5, 2022

The discussion here led me to believe that a tuple ip_network argument might be unsupported, so I've looked it up: the two-tuple form for the (ip network) address constructor parameter is documented (supported since Python 3.5) and the corresponding commit has tests too python/cpython@5fb195f

i.e., the two-tuple support won't go away without breaking backward compatibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ipaddress.ip_network annotations ban tuple arguments
4 participants